package ru.susu.algebra.number;

import java.math.BigInteger;

import ru.susu.algebra.operation.IOperation;
import ru.susu.algebra.pair.Pair;
import ru.susu.algebra.util.NumberUtilities;

/**
 * @author akargapolov
 * @since: 18.10.2009
 */
public class ClearSquaresOperation implements IOperation<BigInteger>
{

	/**
	 * BigInteger N
	 * @param N
	 */
	@Override
	public BigInteger performOperation(Object... sources)
	{
		BigInteger n = (BigInteger)sources[0];
		BigInteger result = BigInteger.valueOf(1);
		for (Pair<Integer, Integer> pair : NumberUtilities.factorization(n))
		{
			int v = pair.getValue() % 2;
			if (v == 1)
				result = result.multiply(BigInteger.valueOf(pair.getKey()));
		}
		return result;
	}

}
